const router = require("koa-router")()

// 获取项目列表
router.get("/", async ctx => {
  
})

// 获取项目详细信息
router.get("/detail", async ctx => {

})

// 创建项目
router.post("/add", async ctx => {
  let {name, avatar, sort, goalMoney, createTime, state, detail, user} = ctx.request.body
  
  if (name && avatar && sort && goalMoney && createTime && state && detail && user) {
    try {
      let res = await ctx.$project.methods.addProject(name, avatar, sort, goalMoney, createTime, state, detail).send({from: user})

      // let projectId = await ctx.$project.methods.getPId().call()

      ctx.body = {state: 1, data: {
        msg: `添加成功, 数据凭证Hash为：${res.transactionHash}`,
        // pId: projectId
      }}
    } catch (e) {
      ctx.body = {state: 0, data: `在调用合约时发生错误，具体错误信息为：${e}`}
    }
  } else {
    ctx.body = {state: 0, data: "在调用合约之前发生错误，可能是参数缺失。"}
  }
})

// 更新项目进展
router.post("update", async ctx => {

})

module.exports = router.routes()